let

 

Let is used to create a new local variable and set its value. A local variable is a variable that only exists within the brackets [] or procedure it was created in, unlike a global variable. It can only be used in the code that comes after its declaration, and takes the form of let variable-name initial-value.

For example,

let my-blue-friends turtles with [ color = blue and shape = “person” ] 
ask my-blue-friends [ forward 1 ]

creates a new variable called my-blue-friends and sets its value to all the blue person-shaped turtles. Then, asking my-blue-friends to move forward moves all blue person-shaped turtles forward. To change the value of the variable after creating it, use set.

 

Try it Yourself

 
 
 
 
 
 
 

What's next?

Once you mastered the let primitive, don't stop there. Check out the resources below to improve your NetLogo skills.

 
Published NetLogo models that use the let primitive:
 
 
Similar primitives:
turtles-own

Declare a variable that belongs to turtles.

Read more
patches-own

Declare a variable that belongs to patches.

Read more
globals

defines variables that can be used throughout the whole model

Read more
set

Set the value of a variable.

Read more
 
Learn another primitive